<?php

namespace App\Http\Controllers;

use App\Services\ServiceFactory;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
    
    protected $_repoService;
    protected $_resource;
    protected function _error(string $_message, $_data = null)
    {
        return ['error_msg' => $_message, 'data' => $_data ?? []];
    }

    protected function _repoService()
    {
        if (!$this->_repoService) {
            return (new ServiceFactory())->createService($this->_resource);
        }
        return $this->_repoService;
    }
}
